<?php
include_once(_CORE_PATH. "entity_prototype.php");
class StructureEntity extends entity_prototype
{
  
	protected $_name = 'structure';
	
	public function SetId($id)
	{
		$this->Set('id', (int)$id);		
	}
	
	public function SetPageParams($params)
	{
		$this->Set('pageParams', new MozgParams('structure/page', $params));
	}
	
	public function GetPageParams()
	{
		$params = $this->Get('pageParams');
		if (!($params instanceof MozgParams))
		{
			$this->SetPageParams($params);
			$params = $this->Get('pageParams');
		}
		
		return $params;
	}	
	
	public function SetModuleParams($params)
	{
		$pageType = $this->GetPageType();
		
		$pageTypes = MozgCfg::GetProp('global/structure//pageTypes');
		
		$pageParamsPath = '';
		if (isset($pageTypes[$pageType]['fieldparams']))
		{
			$pageParamsPath = $pageTypes[$pageType]['fieldparams'];
		}
		
		$this->Set('moduleParams', new MozgParams($pageParamsPath, $params));
	}
	
	public function GetModuleParams()
	{
		$params = $this->Get('moduleParams');
		if (!($params instanceof MozgParams))
		{
			$this->SetModuleParams($params);
			$params = $this->Get('moduleParams');
		}
		
		return $params;
	}

	public function SetPageType($pageType)
	{
		$this->Set('pageType', $pageType);
		
		$params = $this->Get('moduleParams');
		
		if ($params instanceof MozgParams)
		{		
			$this->Set('moduleParams', $params->GetData());
		}	
	}
}